package com.luoyuanxiangvip.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.luoyuanxiangvip.common.enums.ConfigEnum;
import com.luoyuanxiangvip.common.utils.AjaxResult;
import com.luoyuanxiangvip.common.vo.OtherOption;
import com.luoyuanxiangvip.core.service.IConfigService;
import com.luoyuanxiangvip.muisc.service.IMuiscService;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 音乐
 * </p>
 *
 * @author luoyuanxiang <p>luoyuanxiangvip.com</p>
 * @since 2019/7/7
 */
@RestController
public class MusicController {

    @Resource
    @Lazy
    private IMuiscService iMuiscService;
    @Resource
    @Lazy
    private IConfigService iConfigService;

    @ApiOperation(value = "获取音乐列表")
    @GetMapping("/playlist/detail")
    public AjaxResult playList() {
        OtherOption otherOption = iConfigService.getValue(ConfigEnum.OTHER_OPTION.getKey());
        String playListId = otherOption.getPlayListId();
        String playlist = iMuiscService.getPlaylist(playListId);
        return AjaxResult.success("获取音乐列表成功", JSONObject.parseObject(playlist));
    }

    @ApiOperation(value = "获取歌曲详情")
    @GetMapping("/song/detail")
    public AjaxResult song(String id) {
        String songDetail = iMuiscService.getSongDetail(id);
        return AjaxResult.success("获取歌曲详情成功", JSONObject.parseObject(songDetail));
    }

    @ApiOperation(value = "获取歌曲歌词")
    @GetMapping("/lyric")
    public AjaxResult lyric(String id) {
        String lyric = iMuiscService.getLyric(id);
        return AjaxResult.success("获取歌曲歌词成功", JSONObject.parseObject(lyric));
    }

    @ApiOperation(value = "获取歌曲地址")
    @GetMapping("/song/url")
    public AjaxResult url(String id) {
        String songUrl = iMuiscService.getSongUrl(id);
        return AjaxResult.success("获取歌曲地址成功", JSONObject.parseObject(songUrl));
    }
}
